//
// @author 风杨
// @date 22-10-10 下午8:26
// @see <a href="yueny09@163.com">mailTo: yueny09@163.com</a>
//

/// 查询 target 在数组 nums 中的下标位置. 从 0 开始. 找不到则返回 -1
pub fn binary_search_run(nums: Vec<i32>, target: i32) -> i32 {
    let mut size = nums.len();

    if size == 0 {
        return -1;
    }

    let mut base = 0usize;

    while size > 1 {
        let half = size / 2;
        let mid = base + half;

        if nums[mid] <= target {
            base = mid;
        }
        size = size - half;
    }

    if nums[base] == target {
        return base as i32;
    }

    return -1;
}

